package com.sc.nft.admin.consume;

import com.sc.nft.entity.dto.SaasTaskBurialPointDTO;
import com.sc.nft.enums.MessageTopic;
import com.sc.nft.enums.SaasTaskTypeEnum;
import com.sc.nft.helper.MessageQueueHelper;
import com.sc.nft.service.SaasTaskService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;
@RocketMQMessageListener(topic = MessageTopic.DISK_TAKER + "${spring.profiles.active}", consumerGroup = MessageTopic.DISK_TAKER + "${spring.profiles.active}")
@Component
@Slf4j
@RequiredArgsConstructor
public class DiskTakerConsumer implements RocketMQListener<SaasTaskBurialPointDTO> {
    private final SaasTaskService saasTaskService;
    private final MessageQueueHelper messageQueueHelper;
    @Override
    public void onMessage(SaasTaskBurialPointDTO saasTaskBurialPointDTO) {
        // 如果是开户就转发给另外一个mq处理。免得被挤压导致用户以为开户失败了。
        if (saasTaskBurialPointDTO.getTaskType().equals(SaasTaskTypeEnum.OPEN_WALLET_FOR_THE_FIRST_TIME)||saasTaskBurialPointDTO.getTaskType().equals(SaasTaskTypeEnum.FIRST_TIME_OPEN_WALLET_INVITATION)) {
            messageQueueHelper.sendMessage(MessageTopic.OPEN_ACCOUNT, saasTaskBurialPointDTO, saasTaskBurialPointDTO.getTaskType().name());
            return;
        }
        saasTaskService.templateAnalysis(saasTaskBurialPointDTO);
    }
}
